package com.micangcaihang.micang.mvp.task.model;

import com.micangcaihang.common.baserx.RxSchedulers;
import com.micangcaihang.common.http.ApiResult;
import com.micangcaihang.common.http.RxHelper;
import com.micangcaihang.micang.entity.FTaskProductInfoEntity;
import com.micangcaihang.micang.entity.PickerEntity;
import com.micangcaihang.micang.http.ApiService;
import com.micangcaihang.micang.http.FApiService;
import com.micangcaihang.micang.http.request.FTaskProductInfoRequest;
import com.micangcaihang.micang.mvp.task.contract.FTaskProductInfoContract;

import java.util.List;

import io.reactivex.Observable;

/**
 * <pre>
 *     author : Fandy
 *     e-mail : fandayongfly@gmail.com
 *     time   : 2017/07/17
 *     desc   : 风控 产品信息
 *     version: 1.0
 * </pre>
 */

public class FTaskProductInfoModel implements FTaskProductInfoContract.Model {
    @Override
    public Observable<ApiResult<List<PickerEntity>>> getPickerViewData(String type) {
        return ApiService.<ApiResult<List<PickerEntity>>>util_choose(type)
                .compose(RxSchedulers.observableIoToMain())
                .compose(RxHelper.handleResult());
    }

    @Override
    public Observable<ApiResult<FTaskProductInfoEntity>> getProductInfoCostData(String id) {
        return FApiService.<ApiResult<FTaskProductInfoEntity>>risk_product(id)
                .compose(RxSchedulers.observableIoToMain())
                .compose(RxHelper.handleResult());
    }

    /**
     * 加载产品信息费用数据
     *
     * @param product_name
     * @param loan_type
     * @return
     */
    @Override
    public Observable<ApiResult<FTaskProductInfoEntity>> getProductInfoCostData(String product_name, String loan_type) {
        return FApiService.<ApiResult<FTaskProductInfoEntity>>risk_product_temp(product_name,loan_type)
                .compose(RxSchedulers.observableIoToMain())
                .compose(RxHelper.handleResult());
    }

    @Override
    public Observable<ApiResult<Void>> savaProductInfoData(FTaskProductInfoRequest request) {
        return FApiService.<ApiResult<Void>>risk_save_loan(request)
                .compose(RxSchedulers.observableIoToMain())
                .compose(RxHelper.handleResult());
    }
}
